package ooday03;

public class AnimaTest {
    public static void main(String[] args) {
        /*Dog dog = new Dog("小黑","黑",3);
        System.out.println(dog.name);
        dog = null;     //表示空,没有指向任何对象
        dog.eat();      //NullPointerException空指针异常
         */
        //区别1).给引用类型数组元素赋值时需要new一个对象
        //区别2).访问引用类型数组的元素的属性/行为时,需要打点.访问
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑","黑",4);
        dogs[1] = new Dog("小花","黄",5);
        dogs[2] = new Dog("小黄","黄",5);
        System.out.println(dogs[1].name);//输出第二只狗狗的名字
        for(int i = 0;i<dogs.length;i++){
            System.out.println(dogs[i].name);
        }
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("小红","红",6);
        chicks[1] = new Chick("大红","红",3);
        for(int i=0;i<chicks.length;i++){
            chicks[i].layEggs();
        }
        Fish[] fish = new Fish[3];
        fish[0] = new Fish("明太","白",5);
        fish[1] = new Fish("金枪","银",6);
        fish[2] = new Fish("小刀","灰",5);
        for (int i = 0;i<fish.length;i++){
            fish[i].swim();
        }
    }
}
